<html>
<head>
    <meta charset="utf-8">
    <title>流转人</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
    <table  id="assignTable" lay-filter="assignTable"></table>
    <script type="text/html" id="bar">
        {{# if(d.parentTaskId!=null &&  d.parentTaskId!=""){ }}
            <a class="layui-btn layui-btn-xs" lay-event="cancel">取消流转</a>
        {{# } }}
    </script>

    <!--取消-->
    <div id="cancelDiv" style="margin: 20px;display:none;">
        <form class="layui-form" action="">
            <table class="layui-table">
                <tr>
                    <td>发送提醒消息:</td>
                    <td>
                        <!--通知方式-->
                        <div class="layui-input-inline">
                            <#list handlersMap?keys as key>
                            <input type="checkbox" class="layui-input" lay-filter="informType" name="informType" lay-skin="primary" value="${key}" checked="checked"  />
                            <span style="line-height: 44px;">
                                ${handlersMap[key].title }
                            </span>
                            </#list>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>取消原因:</td>
                    <td><textarea  name="opinion" placeholder="请输入取消原因" class="layui-textarea"></textarea></td>
                </tr>
            </table>
        </form>
    </div>


    <script>
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','table','setter','util','layer','commons'], function () {
            var table = layui.table;
            var setter = layui.setter;
            var $ = layui.$;
            var layer = layui.layer;
            var commons = layui.commons;
            //任务id
            var taskId = '${taskId!}';

            //获取消息类型
            function  getInformTypes(element){
                var informTypes = [];
                element.each(function (index,element) {
                    informTypes.push($(element).val());
                });
                return informTypes.toString();
            }

            table.render({
                elem: '#assignTable'
                , title: '流转人列表'
                , url: serverPath.workflowPath+setter.workflowLinkPath+'bpmProTransTo/showAssignee?taskId='+taskId
                , method: 'get'
                , page: true
                , cols: [[
                    {field: 'userName', title: '流转人',  align: 'center'}
                    , {field: 'status', title: '审批状态', align: 'center',templet:function (d) {
                            switch (d.status) {
                                case 1 : return "正在审批";
                                case 2 : return "已审批";
                                default  : return "";
                            }
                        }
                      }
                    , {fixed: 'right', title: '管理', toolbar: '#bar', width: 150, align: 'center'}
                ]]
            });

            //监听行工具事件
            table.on('tool(assignTable)', function (obj) {
                var data = obj.data;
                var parentTaskId = data.parentTaskId;
                var userId = data.userId;
                switch (obj.event){
                    case 'cancel':
                        var layerIndex = layer.open({
                            type:1,
                            title:"取消流转",
                            area: ['500px','350px'],
                            content: $('#cancelDiv'),
                            skin: 'btn-class',
                            btn: ['确定','取消'],
                            btnAlign: 'c',
                            yes: function(index,layero){
                                layer.confirm('确认取消流转任务吗？', function(index) {
                                    var opinion=$("#opinion").val();
                                    //消息通知
                                    var informTypeElement=$("#cancelDiv table [name='informType']:checked");
                                    var informType = getInformTypes(informTypeElement);
                                    var params= {
                                        opinion:opinion,
                                        informType:informType,
                                        taskId:parentTaskId,
                                        userId:userId,};
                                    var url=serverPath.workflowPath + setter.workflowLinkPath+"bpmProTransTo/cancel";
                                    $.post(url,params,function(data){
                                        if(commons._filterRecord(data)){
                                            layer.alert(data.msg, function (index) {
                                                layer.close(index);
                                                layer.close(layerIndex);
                                                table.reload('assignTable');
                                            });
                                        }else{
                                            layer.msg(data.msg, {icon:5});
                                        }
                                    },'json');
                                });
                            },end:function(){

                            }
                        });
                        break;
                }
            });

        });
    </script>
</body>
</html>